//


#import "MB_FirstTableViewCell.h"

//
@interface MB_FirstTableViewCell ()
/** <#Description#>*/
@property (nonatomic, strong) UIView *backview;
/** view*/
@property (nonatomic, strong) UIImageView *backimg;
/** content*/
@property (nonatomic, strong) UILabel *titleLabel;
/** shijian*/
@property (nonatomic, strong) UILabel *dateLabel;

@end

@implementation MB_FirstTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        self.contentView.backgroundColor = [UIColor clearColor]
        [self createTdddsableViewCell];
    }
    return self;
}

// 初始化
-(void)createTdddsableViewCell {
    self.backview = ({
        UIView *view = [[UIView alloc]init];
        view.layer.cornerRadius = 10;
        view.layer.masksToBounds = YES;
        view.backgroundColor = RGB(255 ,228 ,225);
        [self.contentView addSubview:view];
        view;
    });
    
    self.backimg = ({
        UIImageView *view = [[UIImageView alloc]init];
        [self.backview addSubview:view];
        view;
    });
    self.dateLabel = ({
        UILabel *label = [[UILabel alloc]init];
        label.textColor = rgba(90, 90, 90, 1);
        label.font = FontPFRegular(kRWidth(14));
        label.text = @"5-30 10:20";
        [self.backview addSubview:label];
        label;
    });
    self.titleLabel = ({
        UILabel *label = [[UILabel alloc]init];
        label.textColor = rgba(60, 60, 60, 1);
        label.font = FontPFRegular(kRWidth(15));
        label.numberOfLines = 2;
        label.text = @"hekncep'ok',lew";
        [self.backview addSubview:label];
        label;
    });
}
- (void)setNeedsLayout {
    [super setNeedsLayout];
    
    [self.backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(2);
        make.left.mas_offset(3);
        make.right.mas_offset(-3);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRHeight(10));
        make.left.mas_offset(kRHeight(12));
        make.height.mas_equalTo(kRHeight(20));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.dateLabel.mas_bottom).offset(kRHeight(5));
        make.left.mas_equalTo(self.dateLabel);
        make.right.mas_offset(-kRWidth(12));
        make.bottom.mas_equalTo(self.backview.mas_bottom).offset(-kRHeight(10));
    }];
    
}

- (void)setModel:(FirstData *)model {
    _model = model;
    
    self.dateLabel.text = model.date;
    self.titleLabel.text = model.content;
    self.backimg.image = (UIImage*)model.img;
    
    CGSize size = [model.content boundingRectWithSize:CGSizeMake(kMainScreenWidth - kRWidth(30), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin  attributes:@{NSFontAttributeName:self.titleLabel.font} context:nil].size;
    //
    [self.backimg mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(0);
        make.left.mas_offset(0);
        make.right.mas_offset(0);
        make.height.mas_equalTo(size.height + kRHeight(45));
    }];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
